using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
namespace DAL
{
    public class ForumCategories : DAL.DataManager<ForumCategory>
    {
        private static ForumCategories Instance = new ForumCategories();
        static ForumCategories() { }

        public override string TableName
        {
            get { return @"yboard_categories"; }
        }

        protected override void CopyToItem(DataRow Row, ForumCategory Item)
        {
            Item.Name = Convert.ToString(Row["Name"]);
            Item.Position = Convert.ToInt64(Row["Position"]);
        }

        protected override void CopyFromItem(DataManagerQuery query, ForumCategory Item)
        {
            query.AddParam("Name", Item.Name);
            query.AddParam("Position", Item.Position);
        }

        public static ForumCategory Item(Int64 id)
        {
            return Instance.GetItem(id);
        }

        public static List<ForumCategory> All()
        {
            DataManagerQuery query = new DataManagerQuery();
            query.AddSort("Position", Sort.Asc);
            return Instance.GetItems(query);
        }

        public static void Add(ForumCategory Item)
        {
            Instance.Insert(Item);
            Item.Position = Item.ID;
            Save(Item);
        }

        public static void Save(ForumCategory Item)
        {
            Instance.Update(Item);
        }
    }

    public class ForumCategory : DAL.DataManagerRow, IRowPosition
    {
        private string _Name;
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }

        private long _position;
        public long Position
        {
            get
            {
                return _position;
            }
            set
            {
                _position = value;
            }
        }

        public List<Forum> GetForums()
        {
            return Forums.GetByCategory(this);
        }
    }
}